package com.frank.oj.service.entity.group.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.frank.model.entity.contest.Contest;
import com.frank.oj.mapper.GroupContestMapper;
import com.frank.oj.model.vo.ContestVO;
import com.frank.oj.service.entity.group.GroupContestEntityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author frank
 * @Date 2024/5/4
 */
@Service
public class GroupContestEntityServiceImpl extends ServiceImpl<GroupContestMapper,Contest> implements GroupContestEntityService {
    @Resource
    private GroupContestMapper groupContestMapper;
    @Override
    public IPage<ContestVO> getContestList(Integer limit, Integer currentPage, Long gid) {

        IPage<ContestVO> iPage = new Page<>(currentPage, limit);
        List<ContestVO> contestList = groupContestMapper.getContestList(iPage, gid);

        return iPage.setRecords(contestList);
    }

    @Override
    public IPage<Contest> getAdminContestList(Integer limit, Integer currentPage, Long gid) {
        IPage<Contest> iPage = new Page<>(currentPage, limit);

        LambdaQueryWrapper<Contest> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Contest::getGid,gid).orderByDesc(Contest::getId);

        return groupContestMapper.selectPage(iPage, queryWrapper);
    }
}
